/*
 * FreeRTOS Kernel V10.0.1
 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.FreeRTOS.org
 * http://aws.amazon.com/freertos
 *
 * 1 tab == 4 spaces!
 */

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#include "usart.h"

#if defined(__ICCARM__)||defined(__CC__ARM)||defined(__GUNC__)
#include <stdint.h>
#endif

// 断言
#define vAssertCalled(char,int) printf("ERROR: %s, %d\r\n", char, int)
#define configASSERT(x) if((x)==0) vAssertCalled(__FILE__, __LINE__) 

/*-----------------------------------------------------------
 * Application specific definitions.
 *
 * These definitions should be adjusted for your particular hardware and
 * application requirements.
 *
 * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
 * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 
 *
 * See http://www.freertos.org/a00110.html.
 *----------------------------------------------------------*/

/***************************************************************************
						FreeRTOS 基础配置配置选项
***************************************************************************/
#define configUSE_PREEMPTION				1	/* 置1: RTOS使用抢占式调度器; 置0: RTOS使用协作式调度器; */
#define configUSE_TIME_SLICING 				1	/* 置1：使能时间片调度 */
#define configUSE_IDLE_HOOK					0	/* 置0: 不调用空闲任务钩子函数; 置1: 调用空闲任务钩子函数，应用函数必须定义一个空闲任务钩子函数; */
#define configUSE_TICK_HOOK					0	/* 置0: 不调用tick钩子函数; 置1: 调用tick钩子函数，应用函数必须定义一个tick钩子函数; */
#define configCPU_CLOCK_HZ					( ( unsigned long ) 72000000 )	/* 设置外围时钟频率 */	
#define configTICK_RATE_HZ					( ( TickType_t ) 1000 )			/* 设置滴答中断频率. 单位HZ */
#define configMAX_PRIORITIES				( 32 )							/* 设置可分配给任务的最大优先级 */
#define configMINIMAL_STACK_SIZE			( ( unsigned short ) 128 )		/* 设置分配给空闲任务的堆栈的大小 */
#define configTOTAL_HEAP_SIZE				( ( size_t ) ( 16 * 1024 ) )	/* 设置静态分配数组的大小 */
#define configMAX_TASK_NAME_LEN				( 16 )	/* 设置任务名称字节长度 */
#define configUSE_TRACE_FACILITY			0 		/* 启用可视化跟踪调试 */
#define configUSE_16_BIT_TICKS				0		/* 系统节拍计数器变量数据类型， 1 表示为 16 位无符号整形， 0 表示为 32 位无符号整形 */
#define configIDLE_SHOULD_YIELD				1		/* 空闲任务放弃 CPU 使用权给其他同优先级的用户任务 */


/*
 * 大于 0 时启用堆栈溢出检测功能，如果使用此功能
 * 用户必须提供一个栈溢出钩子函数，如果使用的话
 * 此值可以为 1 或者 2，因为有两种栈溢出检测方法 */
#define configCHECK_FOR_STACK_OVERFLOW 		0

/*
** 通用方法:
** 1.configUSE_PORT_OPTIMISED_TASK_SELECTION为0或者硬件不支持这中特殊方法
** 2.可以用于所有FreeRTOS支持的硬件
** 3.完全用C实现，效率低于特殊方法
** 4.不强制要求限制最大可用优先级数目
** 
** 特殊方法:
** 1.必须将configUSE_PORT_OPTIMISED_TASK_SELECTION设置为1
** 2.依赖一个或多个特定架构的汇编指令(一般是类似计算前导零[CLZ]指令)
** 3.比通用方法更高效
** 4.一般强制限定最大可用优先级数目为32
*/
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 	1

#define configUSE_TICKLESS_IDLE 					0	/* 置1：使用低功耗tickless模式 置0：保持系统节拍（tick）中断一直运行 */
#define configUSE_QUEUE_SETS 						1	/* 置1：启用队列 */
#define configUSE_TASK_NOTIFICATIONS 				1	/* 置1：开启任务通知功能 */
#define configUSE_MUTEXES 							0	/* 置0：不使用互斥信号量 */
#define configUSE_RECURSIVE_MUTEXES 				0	/* 置0：不使用递归互斥信号量 */
#define configUSE_COUNTING_SEMAPHORES				1	/* 置1：使用计数信号量 */
#define configQUEUE_REGISTRY_SIZE 					0	/* 设置可以注册的信号量和消息队列个数 */

/***************************************************************************
						FreeRTOS 与协程有关的配置选项
***************************************************************************/
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 						0		/* 启用协程，启用协程以后必须添加文件 croutine.c */
#define configMAX_CO_ROUTINE_PRIORITIES 			( 2 )	/* 协程的有效优先级数目 */

/***************************************************************************
						FreeRTOS 与内存申请有关配置选项
***************************************************************************/
#define configSUPPORT_STATIC_ALLOCATION  			0	/* 置0：不支持静态内存 */
#define configSUPPORT_DYNAMIC_ALLOCATION 			1	/* 置1：支持动态内存申请 */

/***************************************************************************
						FreeRTOS 可选函数配置选项
***************************************************************************/
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_xTaskGetScheduleState 			1
#define INCLUDE_vTaskPrioritySet				1
#define INCLUDE_uxTaskPriorityGet				1
#define INCLUDE_vTaskDelete						1
#define INCLUDE_vTaskCleanUpResources			0
#define INCLUDE_vTaskSuspend					1
#define INCLUDE_vTaskDelayUntil					1
#define INCLUDE_vTaskDelay						1


/*******************************************************************************
						FreeRTOS 与中断有关的配置选项
*******************************************************************************/
/* This is the raw value as per the Cortex-M3 NVIC.  Values can be 255
(lowest) to 0 (1?) (highest). */
#define configKERNEL_INTERRUPT_PRIORITY 		255
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 	191 /* equivalent to 0xb0, or priority 11. */


/* This is the value being used as per the ST library which permits 16
priority values, 0 to 15.  This must correspond to the
configKERNEL_INTERRUPT_PRIORITY setting.  Here 15 corresponds to the lowest
NVIC value of 255. */
#define configLIBRARY_KERNEL_INTERRUPT_PRIORITY	15


/*******************************************************************************
						FreeRTOS与软件定时器有关的配置选项
*******************************************************************************/

#define configUSE_TIMERS				1								// 启用软件定时器
#define configTIMER_TASK_PRIORITY		(configMAX_PRIORITIES - 1)		// 软件定时器优先级
#define configTIMER_QUEUE_LENGTH		10								// 软件定时器队列长度
#define configTIMER_TASK_STACK_DEPTH	(configMINIMAL_STACK_SIZE*2)	// 软件定时器任务堆栈大小

#endif /* FREERTOS_CONFIG_H */

